
//***************  嵌套路由  ******************

import React from 'react'
import {BrowserRouter as Router,Route,Switch,Redirect}  from 'react-router-dom'
// 引入路由相关标签，as起别名
import Admin from '../pages/Home/Home'
import Login from '../pages/Login/Login'
import NotFind from '../pages/NotFind/NotFind'
import User from '../pages/User/User'
import GoodsLlist from '../pages/Goods/List'

class Header extends React.Component{
    render(){
        return(
            <Router>
                <div>
                    <hr/>
                    <Switch>
                        <Route exact path='/'>
                            {/* 路由重定向 Redirect */}
                            <Redirect to='/login'></Redirect>
                        </Route>
                        <Route path='/login' component={Login}></Route>
                        {/* 嵌套路由 */}
                        <Route path='/admin/:id' render= {(props)=>{
                            return <Admin route={props}>
                                <Route exact path='/admin' component={GoodsLlist}></Route>
                                <Route path='/admin/user' component={User}></Route>
                                <Route path='/admin/goods/list' component={GoodsLlist}></Route>
                            </Admin>
                        }}>
                        </Route>
                        {/* Switch 设置没匹配路径，则到404组件页面 */}
                        <Route  component={NotFind}></Route>
                    </Switch>
                </div>
            </Router>
        )
    }
}
export default Header
